let http = require("http");
let fs = require("fs");

const app = http.createServer((req,res)=>{
    let url = new URL(req.url,'http://localhost')
    console.log(url);

    if(url.pathname === '/1.css'){
        let data = fs.readFileSync('./aaa/1.css');
        res.end(data);
    }else if(url.pathname === '/' || url.pathname === '/index.html'){
        let data = fs.readFileSync('./09-demo.html');
        res.end(data);
    }else if(url.pathname === '/img/a.png'){
        let data = fs.readFileSync('./img/1.png');
        res.end(data);
    }
    else if(url.pathname === '/1.js'){
        let data = fs.readFileSync('./js/aaa.js');
        res.end(data);
    }
    else{
        res.setHeader('Content-type','text/html;charset=utf-8')
        res.end('抱歉，您访问的资源不存在 ，404')
    }
})

app.listen(80,()=>{
    console.log("启动成功");
})

// ? key = val & key2=val2 &